//
//  ActivityVC.m
//  HiZhua
//
//  Created by Jpwang on 2017/9/10.
//  Copyright © 2017年 Jpwang. All rights reserved.
//

#import "ActivityVC.h"

@interface ActivityVC ()

@property(weak, nonatomic) IBOutlet UIButton *backBt;
@property(weak, nonatomic) IBOutlet UILabel  *titleLb;
@property(weak, nonatomic) IBOutlet UIWebView *webview;

@property(strong, nonatomic) NSString *customTitle;
@property(strong, nonatomic) NSString *url;

@end

@implementation ActivityVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setTitle:(NSString *)title url:(NSString *)url {
    NSString *uid = @"[uid]";
    NSString *session = @"[session]";
    User *user = [[UserManager shareInstance] isUserLogin] ? [UserManager shareInstance].user : nil;
    url = [url containsString:uid] ? [url stringByReplacingOccurrencesOfString:uid withString:user?intToString(user.uid):@"0"] : url;
    url = [url containsString:session] ? [url stringByReplacingOccurrencesOfString:session withString:user?user.session:@"null"] : url;
    self.customTitle = title;
    self.url = url;
}

- (void)initView {
    [RACObserve(self, url) subscribeNext:^(id x) {
        if (self.url) {
            [self.titleLb setText:self.customTitle?self.customTitle:@"网页浏览"];
            [self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
        }
    }];
    
    [[self.backBt rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
    if (self.url) {
        [self.titleLb setText:self.customTitle?self.customTitle:@"网页浏览"];
        [self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]];
    }
    
}


@end
